package com.shuai.user.service.inner;

import com.shuai.common.constant.ChatType;
import com.shuai.common.service.user.InnerSessionService;
import com.shuai.user.domain.entity.UserSession;
import com.shuai.user.service.UserSessionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DubboService
public class InnerSessionServiceImpl implements InnerSessionService {
    @Autowired
    private UserSessionService userSessionService;

    public long addUserSessionDefault(String question, String userId) {
        UserSession userSession = new UserSession();
        userSession.setUserId(userId);
        userSession.setType(ChatType.ORDINARY_CHAT.getCode());
        userSession.setSessionName(question.length() > 10 ? question.substring(0, 10) : question);
        userSessionService.save(userSession);
        return userSession.getSessionId();
    }
}
